<!--#include file="classData.asp"-->
<!--#include file="classSort.asp"-->
<%
Response.Buffer = True 
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache" 
Response.AddHeader "Pragma", "No-Cache"



	GroupId = CInt(Request.QueryString("CurrentGroup"))
	HomeId = CInt(Request.QueryString("maid"))
	AwayId = CInt(Request.QueryString("mbid"))
	btype = Request.QueryString("btype")
	HomeScore = CInt(Request.QueryString("R1F"))
	AwayScore = CInt(Request.QueryString("R1S"))
	HomePoint = CInt(Request.QueryString("R1FD"))
	AwayPoint = CInt(Request.QueryString("R1SD"))
	

	set HuaObj = new sysData
	HuaObj.sqlConnOpen()

	set SystemRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery SystemRds,"sysVar",QueryStr,0," VarId = 1"
	
	CurrentSeason = SystemRds("CurrentSeason")

	SystemRds.Close


	set UserRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery UserRds,"ClubInfo",QueryStr,0," ManagerId = "&HomeId
	
	HomeClubId = UserRds("ClubId")

	UserRds.Close
	
	set UserBRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery UserBRds,"ClubInfo",QueryStr,0," ManagerId = "&AwayId
	
	AwayClubId = UserBRds("ClubId")

	UserBRds.Close

	HuaObj.p_DbConnection.BeginTrans
	on error resume next


	if (HomeScore + HomePoint) > (AwayScore + AwayPoint) then

	  InsertSql = "UPDATE AreaCup SET IfDone = 1,Score = 3,Goal = "&HomeScore&",Fumble = "&AwayScore&",GoalDif = "&(HomeScore-AwayScore)&",TotalRound = 1,WinNum = 1,Ranking = 1 WHERE ManagerId ="&HomeId&" AND SeasonNum = "&CurrentSeason&" AND CupLevel = 2"
	  HuaObj.SCommand(InsertSql)
	  'Response.Write(InsertSql)
	  
	  InsertSql = "UPDATE AreaCup SET IfDone = 1,Score = 0,Goal = "&AwayScore&",Fumble = "&HomeScore&",GoalDif = "&(AwayScore-HomeScore)&",TotalRound = 1,LostNum = 1,Ranking = 2 WHERE ManagerId ="&AwayId&" AND SeasonNum = "&CurrentSeason&" AND CupLevel = 2"
	  HuaObj.SCommand(InsertSql)
	  'Response.Write(InsertSql)
	  
	  
	  
	  InsertSql = "UPDATE AreaCup SET ManagerId ="&HomeId&",ClubId = "&HomeClubId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 1 AND ManagerId = "&(90000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  InsertSql = "UPDATE CupPlan SET HomeId ="&HomeId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 1 AND HomeId = "&(90000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  InsertSql = "UPDATE CupPlan SET AwayId ="&HomeId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 1 AND AwayId = "&(90000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  
	  InsertSql = "UPDATE AreaCup SET ManagerId ="&AwayId&",ClubId = "&AwayClubId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND ManagerId = "&(91000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  InsertSql = "UPDATE CupPlan SET HomeId ="&AwayId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND HomeId = "&(91000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  
	  
	  

	else
	
	  InsertSql = "UPDATE AreaCup SET IfDone = 1,Score = 0,Goal = "&HomeScore&",Fumble = "&AwayScore&",GoalDif = "&(HomeScore-AwayScore)&",TotalRound = 1, LostNum= 1,Ranking = 2 WHERE ManagerId ="&HomeId&" AND SeasonNum = "&CurrentSeason&" AND CupLevel = 2"
	  HuaObj.SCommand(InsertSql)
	  'Response.Write(InsertSql)
	  
	  InsertSql = "UPDATE AreaCup SET IfDone = 1,Score = 3,Goal = "&AwayScore&",Fumble = "&HomeScore&",GoalDif = "&(AwayScore-HomeScore)&",TotalRound = 1, WinNum= 1,Ranking = 1 WHERE ManagerId ="&AwayId&" AND SeasonNum = "&CurrentSeason&" AND CupLevel = 2"
	  HuaObj.SCommand(InsertSql)
	  'Response.Write(InsertSql)
	  
	  
	  InsertSql = "UPDATE AreaCup SET ManagerId ="&AwayId&",ClubId = "&AwayClubId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 1 AND ManagerId = "&(90000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  InsertSql = "UPDATE CupPlan SET HomeId ="&AwayId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 1 AND HomeId = "&(90000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  InsertSql = "UPDATE CupPlan SET AwayId ="&AwayId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 1 AND AwayId = "&(90000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  
	  InsertSql = "UPDATE AreaCup SET ManagerId ="&HomeId&",ClubId = "&HomeClubId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND ManagerId = "&(91000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  InsertSql = "UPDATE CupPlan SET HomeId ="&HomeId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND HomeId = "&(91000+GroupId)
	  HuaObj.SCommand(InsertSql)
	  
	  
	
	end if
	
	InsertSql = "UPDATE CupPlan SET HomeScore = "&HomeScore&",HomePoint = "&HomePoint&",AwayScore = "&AwayScore&",AwayPoint = "&AwayPoint&",IfDone = 1,MarkDate = '"&Date&"' WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 2 AND HomeId = "&HomeId&" AND AwayId = "&AwayId
	HuaObj.SCommand(InsertSql)


	response.ContentType="text/xml"	
	Response.Write("<?xml version=""1.0"" encoding=""gb2312""?>"&vbcrlf)
	Response.Write("<xml>"&vbcrlf)


	if err.number =0 then  
    	HuaObj.p_DbConnection.CommitTrans  '如果没有conn错误，则执行事务提交
		Response.Write("<Shi ShiId = ""1"">"&vbcrlf)
		Response.Write("</Shi>"&vbcrlf)
	else 
    	HuaObj.p_DbConnection.RollbackTrans '否则回滚
		Response.Write("<Shi ShiId = ""0"">"&vbcrlf)
		Response.Write("</Shi>"&vbcrlf)
	end if

	Response.Write("</xml>"&vbcrlf)

	
	HuaObj.sqlConnClose()


%>
